package com.example.chatroom.repository;

import com.example.chatroom.domain.UserInfo;
import com.example.chatroom.dto.SimpleUserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;


public interface UserInfoRepository extends JpaRepository<UserInfo, Long> {

    UserInfo findByUsername(String username);

    UserInfo findByNickname(String nickname);

    UserInfo findByUsernameAndPassword(String username, String password);

    Boolean existsByNickname(String nickname);

    @Query(nativeQuery = true ,value = "select id from user_info where nickname = ?1")
    Long getIdByNickname(String nickname);

    @Query(nativeQuery = true ,value = "select nickname from user_info where id = ?1")
    String getNicknameById(Long id);

    @Query(value = "select new com.example.chatroom.dto.SimpleUserRole(u.role, u.state) " +
            "from UserInfo u where nickname = ?1")
    SimpleUserRole getUserStateAndRoleByNickname(String nickname);


}
